/* This file is part of the Pardus Economy Planner.

   The Pardus Economy Planner is free software: you can redistribute it
   and/or modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   The Pardus Economy Planner is distributed in the hope that it
   will be useful, but WITHOUT ANY WARRANTY; without even the implied
   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with the Pardus Economy Planner.  If not, see
   <http://www.gnu.org/licenses/>.
*/

/* Utility scripts for Pardus Sector Tool
 * (C) Yassen 2009
 *
 * tile.js
 * Defines functions for getting/setting tile information information.
 *
 * Functions:
 * array  GetSelected()
 * void   Select(id)
 * void   DeSelect(id)
 * bool   IsSelected(id)
 * Tile   Get(id)
 *
 */

Utility.Tile.GetSelected = function(object)
{
  var tiles = Global.DisplayedSector.Tiles;
  var results = [];

  if (object == undefined) // Slow
  {
    for (var i = 0; i < tiles.length; i++)
    {
      var tile = tiles[i];

      if (tile.Selected)
        results.push(tile);
    }
  }
  else // Fast
  {
    var objects = Utility.Object.GetList(object);

    for (var i = 0; i < objects.length; i++)
    {
      var obj = objects[i];

      if (tiles[obj.ID].Selected)
        results.push(tiles[obj.ID]);
    }
  }
  return results;
}

Utility.Tile.Select = function(id)
{
  Global.DisplayedSector.Tiles[id].Selected = true;
  $("nav_" + id).setAttribute("class", "selected");
}

Utility.Tile.DeSelect = function(id)
{
  Global.DisplayedSector.Tiles[id].Selected = false;
  $("nav_" + id).setAttribute("class", TileTypeToAbbr(Global.DisplayedSector.Tiles[id].Type));
}

Utility.Tile.IsSelected = function(id)
{
  return Global.DisplayedSector.Tiles[id].Selected;
}

Utility.Tile.Get = function(id)
{
  return Global.DisplayedSector.Tiles[id];
}